//
//  UIImageView+WebImage.swift
//  Weibo
//
//  Created by cc on 10/19/17.
//  Copyright © 2017 cc. All rights reserved.
//

import SDWebImage

extension UIImageView {
    
    
    /// 隔离 SDWebImage 设置图像函数
    ///
    /// - Parameters:
    ///   - urlString: urlString
    ///   - placeholderImage: placeholderImage
    ///   - isAvatar: 头像
    func cz_setImage (urlString: String? ,placeholderImage: UIImage?, isAvatar: Bool = false ) {
        
        //处理URL
        guard let urlString = urlString, let url = URL(string: urlString) else {
            //设置占位图像
            image = placeholderImage
            
            return
        }
        
        // 可选项 只是用于 swift
        sd_setImage(with: url, placeholderImage: placeholderImage, options: [], progress: nil) { [weak self](image, _, _, _) in
            //完成回调，判断是否是头像
            if isAvatar {
                self?.image = image?.cz_avatarImage(size: self?.bounds.size)
            }
        }
    }
}

